package chapter22

/**
 * Created by alex on 15-4-13.
 */
abstract class List[+T] {

  def isEmpty: Boolean

  def head: T

  def tail: List[T]

}

case object Nil extends List[Nothing] {

  override def isEmpty = true

  def head: Nothing =
    throw new NoSuchElementException("head of empty list")

  def tail: List[Nothing] =
    throw new NoSuchElementException("tail of empty list")
}

final case class ::[T](head: T, tail: List[T]) extends List[T] {

//  def head = hd
//
//  def tail = tl

  override def isEmpty: Boolean = false

//  def length: Int =
//    if(isEmpty) 0 else 1 + tail.length
//
//  def drop(n: Int): List[T] =
//    if(isEmpty) Nil
//    else if (n <= 0) this
//    else tail.drop(n - 1)
//
//  def map[U](f: T => U):List[U] =
//    if(isEmpty) Nil
//    else f(head) :: tail.map(f)

//  def ::[U >: T](x: U): List[U] = new scala.::(x, this)
}